package com.catmiao.rdd.operate.transform;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.Arrays;
import java.util.List;

/**
 * @author ChengMiao
 * @title: Transfer_01_Map
 * @projectName spark_study
 * @description: TODO
 * @date 2024/11/25 16:27
 */
public class Transfer_18_Action_Serial2 {

    public static void main(String[] args) throws InterruptedException {

        final SparkConf conf = new SparkConf();
        conf.setAppName("appName");
        conf.setMaster("local[*]");

        final JavaSparkContext jsc = new JavaSparkContext(conf);


        List<String> list = Arrays.asList("Hadoop","Spark","Hive","Flink");
        JavaRDD<String> rdd = jsc.parallelize(list, 2);

//        rdd.foreach(item->{
//            System.out.println(item);
//        });

        // 切换为lambda后报错
        /**
         * Caused by: java.io.NotSerializableException: java.io.PrintStream
         * JDK1.8函数式编程其实采用的对象模拟出来的，将System.out对象传递到了Executor端
         */
        rdd.foreach(System.out::println);
        jsc.close();


    }
}




